package likou.offer;

/**
 * @Info:
 * @Author: 唐小尊
 * @Date: 2020/8/16  9:03
 */
public class _24 {
    public static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        head.next = new ListNode(2);
        head.next.next = new ListNode(3);
        head.next.next.next = new ListNode(4);
        head.next.next.next.next = new ListNode(5);
        ListNode daan = reverseList(head);
        while (daan!=null){
            System.out.println(daan.val);
            daan = daan.next;
        }
    }

    public static ListNode reverseList(ListNode head) {
        ListNode daan = new ListNode(head.val);
        head = head.next;
        while (head != null) {
            ListNode temp = new ListNode(head.val);
            head = head.next;
            temp.next = daan;
            daan = temp;
        }
        return daan;
    }
}
